package niu.modao.modao.utils;

import android.content.Context;
import android.content.SharedPreferences;
import android.content.pm.PackageInfo;
import android.content.pm.PackageManager;
import niu.modao.modao.BaseApp;

/**
 * @author niu
 * @fucntion  是个工具类
 */
public class Utils {


    public  static  boolean isFrist(){
        Context context = BaseApp.getContext();
        SharedPreferences sp =context.getSharedPreferences("isFrist", context.MODE_PRIVATE);
        boolean isFirst = sp.getBoolean("isFrist" , true);
        int versionCode = sp.getInt("versionCode",1);//默认版本号为1
        if (isFirst || getVersionCode(context)>versionCode){
            sp.edit().putBoolean("isFrist" ,false).commit();
            sp.edit().putInt("versionCode",getVersionCode(context)).commit();
        }
        return  isFirst;
    }

    /**
     *  获得当前的系统版本号
     * @param context
     * @return
     */

    private static int getVersionCode(Context context) {
        PackageManager manger = context.getPackageManager();
        PackageInfo info = null;
        try {
            info = manger.getPackageInfo(context.getPackageName(),0);
        } catch (PackageManager.NameNotFoundException e) {
            e.printStackTrace();
        }
        return info.versionCode;
    }

}
